import { makeAutoObservable } from 'mobx';
import * as api from './api';

export default class DashboardStore {
  /* 查询参数
   */
  query = {}

  orderType = {
    ccOrder: 1,
    shuttleOrder: 2,
    busOrder: 3,
  };

  queryCC = {
    orderType: 1,
    ...this.query,
  }

  queryST = {
    orderType: 2,
    ...this.query,
  }

  queryBUS = {
    orderType: 3,
    ...this.query,
  }

  queryCT = {
    orderType: 3,
    ...this.query,
  }

  loading = {
    cc: false,
    st: false,
    bus: false,
    ct: false,
  };

  ccOrder = [];
  busOrder = [];
  shuttleOrder = [];
  ct = [];
  pipeData = [];

  /**
  * 用户注册状态
  * 0-查询所有匿名用户
  * 1-查询所有真实注册用户
  * -1-查询所有用户(默认)
  */
  _userTypes = [
    {
      label: '匿名用户',
      value: 0,
    },
    {
      label: '真实注册用户',
      value: 1,
    },
    {
      label: '所有用户',
      value: -1,
    },
  ];

  constructor(rootStore) {
    this.rootStore = rootStore;
    makeAutoObservable(this, { rootStore: false });
  }

  /**
 * 初始化包车订单搜索条件
 */
  resetQuery() {
    this.queryCC = { ...this.query };
    this.queryST = { ...this.query };
    this.queryBUS = { ...this.query };
    this.queryCT = { ...this.query };
  }

  * get() {
    this.pipeData = yield api.getPipe();
  }

  * fetchCC(args) {
    Object.assign(this.queryCC, { ...args });
    this.loading.cc = true;
    try {
      this.ccOrder = yield api.getOrderBar({ ...this.queryCC });
    } finally {
      this.loading.cc = false;
    }
  }

  * fetchST(args) {
    Object.assign(this.queryST, { ...args });
    this.loading.st = true;
    try {
      this.shuttleOrder = yield api.getOrderBar({ ...this.queryST });
    } finally {
      this.loading.st = false;
    }
  }

  * fetchBUS(args) {
    Object.assign(this.queryBUS, { ...args });
    this.loading.bus = true;
    try {
      this.busOrder = yield api.getOrderBar({ ...this.queryBUS });
    } finally {
      this.loading.bus = false;
    }
  }

  * fetchCT(args) {
    Object.assign(this.queryCT, { ...args });
    this.loading.ct = true;
    try {
      this.ct = yield api.getCustom({ ...this.queryCT });
    } finally {
      this.loading.ct = false;
    }
  }
}
